
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
       <button>点击发送axios</button>
       <div id='showMsg'></div>
</body>
</html>
<script>

document.getElementsByTagName("button")[0].onclick=()=>{
    //alert("click")
    // 为给定 ID 的 user 创建请求
    /* axios.get("/stu/getallstudents")
    .then(function (response) {
        //console.log(response);
        let msg = response.data.msg;
        document.getElementById("showMsg").innerHTML=msg

    })
    .catch(function (error) {
        console.log(error);
    }); */
    //post
   /*  axios.post("/stu/addstudent")
          .then((response)=>{
            let msg = response.data.msg;
        document.getElementById("showMsg").innerHTML=msg
          }) */
     //put
    /* axios.put("/stu/updatestudent")
          .then((response)=>{
            let msg = response.data.msg;
        document.getElementById("showMsg").innerHTML=msg
          }) */

         /*  axios.delete("/stu/delstudent")
          .then((response)=>{
            let msg = response.data.msg;
        document.getElementById("showMsg").innerHTML=msg
          })  */

       //配置选项的写法
        /*   axios({
            method:"delete",
            url:"/stu/delstudent" 
          }).then((response)=>{
            let msg = response.data.msg;
        document.getElementById("showMsg").innerHTML=msg
          }) */

          //传递参数（restful风格的参数）
          /* axios.get("/stu/getstudentById/100121/张三")
               .then((res)=>{
                let msg = res.data.msg;
        document.getElementById("showMsg").innerHTML=msg
          
               }) */

        /* axios.get("/stu/getstudentById?stuid=2000&stuname=李四")
               .then((res)=>{
                let msg = res.data.msg;
        document.getElementById("showMsg").innerHTML=msg
          
               }) */

              /*  axios.get("/stu/getstudentById",
               {
                params:{
                stuid:3001,
                stuname:"王五" 
               }
               })
               .then((res)=>{
                let msg = res.data.msg;
        document.getElementById("showMsg").innerHTML=msg
          
               }) */

               //post
               /* axios.post("/stu/addstudent",{
                stuname:"新来的",
                stugender:"男",
                stuage:20,
                stuclassid:1
               }).then((res)=>{
                 //....
               }) */
      //配置选项写法
      axios({
          method:"post",
          url:"/stu/addstudent",
          data:{
            stuname:"新来的222",
                stugender:"女",
                stuage:28,
                stuclassid:2
          }
      })         


}

</script>